package com.zwps.common.controller.response.message;

import java.util.List;

import com.github.pagehelper.Page;
import com.zwps.common.api.model.vo.PageInfoVO;
import com.zwps.common.core.exception.status.CommonExceptionStatus;
import com.zwps.extra.http.response.message.DefaultResponseDataMessage;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

@Schema(description = "响应分页数据基础结构")
@Getter
public class ResponseDataPageMessage<T> extends DefaultResponseDataMessage<PageInfoVO<T>> {

    @Schema(description = "处理结果")
    private boolean success;

    @Schema(description = "处理结果状态码")
    @Override
    public Integer getCode() {
        return super.getCode();
    }
    
    @Schema(description = "处理结果消息")
    @Override
    public String getMessage() {
        return super.getMessage();
    }
    
    @Schema(description = "响应数据")
    @Override
    public PageInfoVO<T> getData() {
        return super.getData();
    }
    
    public ResponseDataPageMessage() {
    }

    public ResponseDataPageMessage(Integer code, String message, Page<T> page) {
        super(code, message);
        super.data = new PageInfoVO<T>(page.getPageNum(), page.getPageSize(), page.getPages(), page.getTotal(),
                page.getResult());
        success = true;
    }
    
    public ResponseDataPageMessage(Integer code, String message, PageInfoVO<T> page) {
        super(code, message);
        super.data = page;
        success = true;
    }

    public ResponseDataPageMessage(Integer code, String message, int pageNum, int pageSize, int pages, long total,
            List<T> list) {
        super(code, message);
        super.data = new PageInfoVO<T>(pageNum, pageSize, pages, total, list);
    }

    public ResponseDataPageMessage(Integer code, String message, Page<T> page, List<T> list) {
        super(code, message);
        super.data = new PageInfoVO<T>(page.getPageNum(), page.getPageSize(), page.getPages(), page.getTotal(), list);
        success = true;
    }

    public static <T> ResponseDataPageMessage<T> data(Page<T> page) {
        CommonExceptionStatus status = CommonExceptionStatus.USER_ACTION_SUCCESS;
        return new ResponseDataPageMessage<T>(status.getCode(), status.getDescribe(), page);
    }

    public static <T> ResponseDataPageMessage<T> data(Page<?> page, List<T> list) {
        CommonExceptionStatus status = CommonExceptionStatus.USER_ACTION_SUCCESS;
        return new ResponseDataPageMessage<T>(status.getCode(), status.getDescribe(), page.getPageNum(),
                page.getPageSize(), page.getPages(), page.getTotal(), list);
    }
    
    public static <T> ResponseDataPageMessage<T> data(PageInfoVO<T> page) {
        CommonExceptionStatus status = CommonExceptionStatus.USER_ACTION_SUCCESS;
        return new ResponseDataPageMessage<T>(status.getCode(), status.getDescribe(), page);
    }

}
